import os
import sys

def get_resource_path():
    """获取资源文件路径，兼容开发环境和打包环境"""
    if getattr(sys, 'frozen', False):
        # 打包后的环境
        application_path = os.path.dirname(sys.executable)
        # 检查是否存在_internal目录（PyInstaller打包）
        internal_path = os.path.join(application_path, '_internal')
        if os.path.exists(internal_path):
            return application_path, internal_path
        else:
            return application_path, application_path
    else:
        # 开发环境
        script_path = os.path.dirname(os.path.realpath(__file__))
        root_path = os.path.dirname(script_path)  # 上一级目录
        return root_path, root_path

ROOT_PATH, INTERNAL_PATH = get_resource_path()
RES_PATH = os.path.join(INTERNAL_PATH, "components", "res")
IMAGE_PATH = os.path.join(RES_PATH, "images")
ICON_PATH = os.path.join(IMAGE_PATH, "icon.png")
USER_IMG_PATH = os.path.join(IMAGE_PATH, "user.jpg")
CONFIG_PATH = os.path.join(ROOT_PATH, "config.ini")
CONFIG_TEMPLATE_PATH = os.path.join(RES_PATH, "template", "config.ini.template")
NODEJS_PATH = os.path.join(RES_PATH, "node.exe")

# Linux系统请在这里设置NodeJs路径
# NODEJS_PATH = os.path.join(os.path.dirname("/usr/local/bin/"), "node")

CAPTCHA_PATH = os.path.join(INTERNAL_PATH, "captcha")

CAPTCHA_ACTOKEN_JS_PATH = os.path.join(CAPTCHA_PATH, "js", "actoken.js")
CAPTCHA_CB_JS_PATH = os.path.join(CAPTCHA_PATH, "js", "cb.js")
CAPTCHA_FP_JS_PATH = os.path.join(CAPTCHA_PATH, "js", "fp.js")
CAPTCHA_SC_JS_PATH = os.path.join(CAPTCHA_PATH, "js", "secureCaptcha.js")